<template>
	<view class="pages">
		<view class="t-c logo">
			<image src="https://study108.oss-rg-china-mainland.aliyuncs.com/tabber/index1.png" mode="widthFix">
			</image>
		</view>

		<view class="t-c m-b-30">
			{{`${hello}好，${userInfo.name || '同学'}`}}
		</view>
		<view class="flex-between-row flex-warp">
			<view @click="goLink(item.link)" class="quick-link flex-center-column m-b-30"
				v-for="(item,index) in quickLinkList" :key="index">
				<image :src="item.image" mode=""></image>
				<view class="col-6 f-30 m-t-10">{{item.label}}</view>
			</view>
		</view>

		<view class="f-w800 f-36 m-y-30">校园新闻</view>
		<view @click="goLink(`/pages/detail/news?id=${item.id}`)" class="card m-b-30" v-for="(item,index) in news"
			:key="index">
			<view class="flex-between-column flex-1">
				<view class="u-line-2">{{item.title}}</view>
				<view class="flex-1"></view>
				<view class="col-9 f-26">{{item.time}}</view>
			</view>
			<image :src="item.image" mode=""></image>
		</view>
		<Tabbar :current="0"></Tabbar>
		<u-loadmore :status="status" loadingText="正在加载中,上下滑动重新加载" />
		<u-back-top :scrollTop="scrollTop" bottom="100" :customStyle="{'background-color':'#2979ff'}" :iconStyle="{
				'fontSize': '40rpx',
				'color':'#FFF' }"></u-back-top>
	</view>
</template>

<script>
	import Tabbar from '@/components/tabbar.vue'
	import {
		getLinkDetail
	} from '@/api/index.js'
	import {
		getNewsListDetail
	} from '@/api/list.js'
	export default {
		components: {
			Tabbar
		},
		computed: {
			userInfo() {
				return this.$store.getters.userInfo
			}
		},
		onShow() {
			uni.hideTabBar({
				animation: false
			})
			let time = new Date()
			let hour = time.getHours()
			switch (true) {
				case hour >= 5 && hour < 8:
					this.hello = '早上'
					break;
				case hour >= 8 && hour < 12:
					this.hello = '上午'
					break;
				case hour >= 12 && hour < 14:
					this.hello = '中午'
					break;
				case hour >= 14 && hour < 18:
					this.hello = '下午'
					break;
				case hour >= 18 || hour < 5:
					this.hello = '晚上'
					break;
			}
		},
		onLoad() {
			this.getLink()
			this.getNewsList()
		},

		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onReachBottom() {
			this.getNewsList()
		},
		data() {
			return {
				status: 'nomore',
				hello: '你',
				nickname: '同学',
				quickLinkList: [],
				news: [],
				scrollTop: 0,
				indexInfo: {},
				page: 1,
			}
		},
		methods: {
			async getLink() {
				const res = await getLinkDetail()
				if (res.code === 200) {
					this.quickLinkList = res.data
				}
			},
			async getNewsList() {
				this.status = 'loading'
				const res = await getNewsListDetail({
					page: this.page,
					limit: 8,
				})
				this.status = 'nomore'
				if (res.code === 200) {
					if (res.data.length === 0) return
					this.page++
					this.news.push(...res.data)
				}
			}
		}
	}
</script>

<style>
	page {
		background: linear-gradient(-225deg, rgba(254, 214, 227, 0.5) 22.22%, rgba(168, 237, 234, 0.5) 51.08%, rgba(254, 214, 227, 0.5) 78.34%);
	}
</style>

<style lang="scss" scoped>
	.pages {
		padding: 0rpx 30rpx 160rpx;
	}

	.logo {
		padding-top: 30rpx;

		image {
			width: 200rpx;
		}
	}

	.quick-link {
		width: 22%;

		image {
			width: 120rpx;
			height: 120rpx;
		}
	}

	.card {
		display: flex;
		justify-content: space-between;
		padding: 20rpx;
		border-radius: 20rpx;
		background-color: rgba(255, 255, 255, 0.8);

		image {
			margin-left: 30rpx;
			width: 246rpx;
			height: 160rpx;
			border-radius: 12rpx;
		}
	}
</style>
